<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--
 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
 * Copyright (C) 2003-2010 Frederico Caldeira Knabben
 *
 * == BEGIN LICENSE ==
 *
 * Licensed under the terms of any of the following licenses at your
 * choice:
 *
 *  - GNU General Public License Version 2 or later (the "GPL")
 *    http://www.gnu.org/licenses/gpl.html
 *
 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
 *    http://www.gnu.org/licenses/lgpl.html
 *
 *  - Mozilla Public License Version 1.1 or later (the "MPL")
 *    http://www.mozilla.org/MPL/MPL-1.1.html
 *
 * == END LICENSE ==
-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<title>FCKDomTools - Tests for JsUnit</title>
	<script src="../../../editor/_source/fckscriptloader.js" type="text/javascript"></script>
	<script type="text/javascript" src="tests.js"></script>
	<script type="text/javascript" src="../_jsunit/app/jsUnitCore.js"></script>
	<script type="text/javascript">

FCKScriptLoader.Load( 'FCKDomTools' ) ;

	</script>
	<script type="text/javascript">

var _BodyHtml ;

function setUpPage()
{
	_BodyHtml = document.body.innerHTML ;
	setUpPageStatus = 'complete' ;
}

// JsUnit special function called before every test start.
function setUp()
{
	// Reset the body (because of changes by test functions).
	document.body.innerHTML = _BodyHtml ;
}

// Use window.onload to call a test outside JsUnit (for debugging).
// The "tests.js" script must be commented.
//window.onload = function()
//{
//	test_GetNextSourceNode() ;
//}

	</script>
	<script type="text/javascript">

function test_GetNextSourceNode()
{
	var el = document.getElementById( 'xP' ) ;

	el = FCKDomTools.GetNextSourceNode( el ) ;
	assertEquals( 'Step 1', document.getElementById( 'xP' ).firstChild, el ) ;

	el = FCKDomTools.GetNextSourceNode( el ) ;
	assertEquals( 'Step 2', document.getElementById( 'xSpan' ), el ) ;

	el = FCKDomTools.GetNextSourceNode( el ) ;
	assertEquals( 'Step 3', document.getElementById( 'xSpan' ).firstChild, el ) ;

	el = FCKDomTools.GetNextSourceNode( el ) ;
	assertEquals( 'Step 4', document.getElementById( 'xSpan' ).nextSibling, el ) ;

	el = FCKDomTools.GetNextSourceNode( el ) ;
	assertEquals( 'Step 5', document.getElementById( 'xBR' ), el ) ;

	el = FCKDomTools.GetNextSourceNode( el ) ;
	assertEquals( 'Step 6', document.getElementById( 'xBR' ).nextSibling, el ) ;

	el = FCKDomTools.GetNextSourceNode( el ) ;
	assertEquals( 'Step 8', document.getElementById( 'xHR' ), el ) ;

	el = FCKDomTools.GetNextSourceNode( el ) ;
	assertEquals( 'Step 9', document.getElementById( 'xHR' ).nextSibling, el ) ;
}

function test_HasAttribute()
{
	assertTrue( 'Test 1',
		FCKDomTools.HasAttribute( document.getElementById( 'xH1' ), 'class' ) ) ;

	assertFalse( 'Test 2',
		FCKDomTools.HasAttribute( document.getElementById( 'xH1' ), 'title' ) ) ;

	assertFalse( 'Test 3',
		FCKDomTools.HasAttribute( document.getElementById( 'xP' ), 'class' ) ) ;

	assertTrue( 'Test 4',
		FCKDomTools.HasAttribute( document.getElementById( 'xH2' ), 'style' ) ) ;

	assertTrue( 'Test 5',
		FCKDomTools.HasAttribute( document.getElementById( 'xIMG' ), 'src' ) ) ;

	assertTrue( 'Test 6',
		FCKDomTools.HasAttribute( document.getElementById( 'xIMG' ), 'alt' ) ) ;

	assertFalse( 'Test 7',
		FCKDomTools.HasAttribute( document.getElementById( 'xIMG' ), 'width' ) ) ;

	assertFalse( 'Test 8',
		FCKDomTools.HasAttribute( document.getElementById( 'xIMG' ), 'unknown' ) ) ;
}

function test_BreakParent_1()
{
	var p = document.getElementById( 'xBreakParent_P1' ) ;

	FCKDomTools.BreakParent( p.getElementsByTagName('span')[0], p.getElementsByTagName('i')[0] ) ;

	assertEquals( 'SPAN breaks I', '<b>this <i>is some</i><span></span><i> sample</i> test text</b>', GetTestInnerHtml( p ) ) ;
}

function test_BreakParent_2()
{
	var p = document.getElementById( 'xBreakParent_P1' ) ;

	FCKDomTools.BreakParent( p.getElementsByTagName('span')[0], p.getElementsByTagName('b')[0] ) ;

	assertEquals( 'SPAN breaks B', '<b>this <i>is some</i></b><span></span><b><i> sample</i> test text</b>', GetTestInnerHtml( p ) ) ;
}

function test_BreakParent_3()
{
	var p = document.getElementById( 'xBreakParent_P2' ) ;

	FCKDomTools.BreakParent( p.getElementsByTagName('span')[0], p.getElementsByTagName('i')[0] ) ;

	assertEquals( 'SPAN breaks I', '<b><i></i><span>test</span><i></i></b>', GetTestInnerHtml( p ) ) ;
}

function test_BreakParent_4()
{
	var p = document.getElementById( 'xBreakParent_P2' ) ;

	FCKDomTools.BreakParent( p.getElementsByTagName('span')[0], p.getElementsByTagName('b')[0] ) ;

	assertEquals( 'SPAN breaks B', '<b><i></i></b><span>test</span><b><i></i></b>', GetTestInnerHtml( p ) ) ;
}

function test_BreakParent_5()
{
	var p = document.getElementById( 'xBreakParent_P2' ) ;

	FCKDomTools.BreakParent( p.getElementsByTagName('i')[0], p.getElementsByTagName('b')[0] ) ;

	assertEquals( 'I breaks B', '<b></b><i><span>test</span></i><b></b>', GetTestInnerHtml( p ) ) ;
}

	</script>
</head>
<body>
	<h1 id="xH1" class="Test">
		Test page for FCKeditor
	</h1>
	<p id="xP">
		This document contains various markup features commonly used by content editors
		or "<span id="xSpan" lang="fr">r&eacute;dacteurs de contenu</span>" as they are
		called in France.<br id="xBR" />
		It is important that a WYSIWYG tool has features that are easily available for the
		editor. If not, there is a risk that content won't receive proper markup. Examples
		of commonly found content are:</p><hr id="xHR" />
	<h2 id="xH2" style="background-color: Silver">
		Test procedure
	</h2>
	This text has no block tag. It should be corrected when working with the enter key
	set to "p" or "div" tags. The "br" configuration should not make changes instead.
	<p>
		In the test we will try to recreate this document using the editor tools. To make
		sure tables can be inserted <em>properly</em> we re-visit banana import statistics
		from 1998.
	</p>
	<p>
		This paragraph has and image at the very end of its contents.<img id="xIMG" src="http://www.fckeditor.net/images/logotop.gif"
			alt="" />
	</p>
	<p id="xBreakParent_P1"><b>This <i>is some<span></span> sample</i> test text</b></p>
	<p id="xBreakParent_P2"><b><i><span>test</span></i></b></p>
</body>
</html>
